import java.awt.*;
import java.util.ArrayList;
import java.util.Vector;

/**
 * Created by berkbozkurt on 07/03/15.
 */
public class LevelManager {

    private int level;
    private Dimension size;
    private BrickFactory brickFactory;

    public LevelManager(Dimension size) {
        level = 1;
        this.size = size;
        brickFactory = new BrickFactory();

    }

    public Vector<Brick> constructLevel(int level) {
        // Rows
        Vector<Brick> bricks = new Vector<>();
        int x = 0;
        int y = 0;
        int brickWidth = 0;
        int brickHeight = 0;
        int numberOfBricksInColumn = 0;
        int numberOfBricksInRow = 0;
        int xSpaceBetweenBricks = 0;
        int ySpaceBetweenBricks = 0;

        String brickType = null;

        if (level == 1) {
            brickType = "SOFT";
            brickWidth = 100;
            brickHeight = 40;
            numberOfBricksInColumn =3;
            numberOfBricksInRow = 3;
            xSpaceBetweenBricks = (size.width - (numberOfBricksInRow * brickWidth)) / (numberOfBricksInRow + 1);
            ySpaceBetweenBricks = (size.height/2 - (numberOfBricksInColumn * brickHeight)) / (numberOfBricksInColumn + 1);
        }
        else if(level == 2) {
            brickType = "MEDIUM";
            brickWidth = 100;
            brickHeight = 30;
            numberOfBricksInColumn = 3;
            numberOfBricksInRow = 3;
            xSpaceBetweenBricks = (size.width - (numberOfBricksInRow * brickWidth)) / (numberOfBricksInRow + 1);
            ySpaceBetweenBricks = (size.height/2 - (numberOfBricksInColumn * brickHeight)) / (numberOfBricksInColumn + 1);
        }
        else if(level == 3) {
            brickType = "HARD";
            brickWidth = 40;
            brickHeight = 10;
            numberOfBricksInColumn = 3;
            numberOfBricksInRow = 3;
            xSpaceBetweenBricks = (size.width - (numberOfBricksInRow * brickWidth)) / (numberOfBricksInRow + 1);
            ySpaceBetweenBricks = (size.height/2 - (numberOfBricksInColumn * brickHeight)) / (numberOfBricksInColumn + 1);
        }
        else {
            // Give exception (Wrong Input)
            return null;
        }
        // Rows 1....4
        for (int i = 0; i < numberOfBricksInColumn; i++) {
            // Columns 1...10
            for (int j = 0; j < numberOfBricksInRow; j++) {
                // Adjust location of brick
                x = (xSpaceBetweenBricks * (i + 1)) + (i * brickWidth);
                y = (ySpaceBetweenBricks * (j + 1)) + (j * brickHeight);
                // Create brick
                Brick brick = brickFactory.createBrick(brickType);
                brick.setSize(new Dimension(brickWidth, brickHeight));
                brick.setLocation(x, y);
                bricks.add(brick);
            }
        }
        return bricks;

    }
}
